{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# '''\n",
    "# 异或\n",
    "# 0^0 = 0\n",
    "# 0^1 = 1\n",
    "# 1^0 = 1\n",
    "# 1^1 = 0\n",
    "# '''\n",
    "\n",
    "# 注意不能用一条直线来分类，单层感知器对这个是不能起作用的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.81037767]\n",
      " [-0.50969944]\n",
      " [ 0.01244946]]\n"
     ]
    }
   ],
   "source": [
    "#输入数据，第1列式偏置，234列式异或的数值，见上\n",
    "X = np.array([[1,0,0],\n",
    "              [1,0,1],\n",
    "              [1,1,0],  \n",
    "              [1,1,1]])\n",
    "#标签\n",
    "Y = np.array([[-1],  # 标签是1和-1两种\n",
    "              [1],\n",
    "              [1],\n",
    "              [-1]])\n",
    "\n",
    "#权值初始化，3行1列，取值范围-1到1\n",
    "W = (np.random.random([3,1])-0.5)*2\n",
    "\n",
    "print(W)\n",
    "#学习率设置\n",
    "lr = 0.11\n",
    "#神经网络输出\n",
    "O = 0\n",
    "\n",
    "def update():\n",
    "    global X,Y,W,lr\n",
    "    O = np.sign(np.dot(X,W)) # shape:(3,1)\n",
    "    W_C = lr*(X.T.dot(Y-O))/int(X.shape[0])\n",
    "    W = W + W_C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.70037767]\n",
      " [-0.56469944]\n",
      " [-0.04255054]]\n",
      "0\n",
      "[[ 0.59037767]\n",
      " [-0.61969944]\n",
      " [-0.09755054]]\n",
      "1\n",
      "[[ 0.59037767]\n",
      " [-0.56469944]\n",
      " [-0.09755054]]\n",
      "2\n",
      "[[ 0.53537767]\n",
      " [-0.56469944]\n",
      " [-0.09755054]]\n",
      "3\n",
      "[[ 0.53537767]\n",
      " [-0.50969944]\n",
      " [-0.09755054]]\n",
      "4\n",
      "[[ 0.48037767]\n",
      " [-0.50969944]\n",
      " [-0.09755054]]\n",
      "5\n",
      "[[ 0.48037767]\n",
      " [-0.45469944]\n",
      " [-0.09755054]]\n",
      "6\n",
      "[[ 0.42537767]\n",
      " [-0.45469944]\n",
      " [-0.09755054]]\n",
      "7\n",
      "[[ 0.42537767]\n",
      " [-0.39969944]\n",
      " [-0.09755054]]\n",
      "8\n",
      "[[ 0.37037767]\n",
      " [-0.39969944]\n",
      " [-0.09755054]]\n",
      "9\n",
      "[[ 0.37037767]\n",
      " [-0.34469944]\n",
      " [-0.09755054]]\n",
      "10\n",
      "[[ 0.31537767]\n",
      " [-0.34469944]\n",
      " [-0.09755054]]\n",
      "11\n",
      "[[ 0.31537767]\n",
      " [-0.28969944]\n",
      " [-0.09755054]]\n",
      "12\n",
      "[[ 0.26037767]\n",
      " [-0.28969944]\n",
      " [-0.09755054]]\n",
      "13\n",
      "[[ 0.26037767]\n",
      " [-0.23469944]\n",
      " [-0.09755054]]\n",
      "14\n",
      "[[ 0.20537767]\n",
      " [-0.23469944]\n",
      " [-0.09755054]]\n",
      "15\n",
      "[[ 0.20537767]\n",
      " [-0.17969944]\n",
      " [-0.09755054]]\n",
      "16\n",
      "[[ 0.15037767]\n",
      " [-0.17969944]\n",
      " [-0.09755054]]\n",
      "17\n",
      "[[ 0.15037767]\n",
      " [-0.12469944]\n",
      " [-0.09755054]]\n",
      "18\n",
      "[[ 0.09537767]\n",
      " [-0.12469944]\n",
      " [-0.09755054]]\n",
      "19\n",
      "[[ 0.15037767]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "20\n",
      "[[ 0.04037767]\n",
      " [-0.12469944]\n",
      " [-0.09755054]]\n",
      "21\n",
      "[[ 0.09537767]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "22\n",
      "[[ 0.04037767]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "23\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "24\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "25\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "26\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "27\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "28\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "29\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "30\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "31\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "32\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "33\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "34\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "35\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "36\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "37\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "38\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "39\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "40\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "41\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "42\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "43\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "44\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "45\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "46\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "47\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "48\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "49\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "50\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "51\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "52\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "53\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "54\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "55\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "56\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "57\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "58\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "59\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "60\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "61\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "62\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "63\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "64\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "65\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "66\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "67\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "68\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "69\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "70\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "71\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "72\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "73\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "74\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "75\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "76\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "77\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "78\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "79\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "80\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "81\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "82\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "83\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "84\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "85\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "86\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "87\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "88\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "89\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "90\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "91\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "92\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "93\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "94\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "95\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "96\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "97\n",
      "[[ 0.09537767]\n",
      " [-0.01469944]\n",
      " [ 0.01244946]]\n",
      "98\n",
      "[[-0.01462233]\n",
      " [-0.06969944]\n",
      " [-0.04255054]]\n",
      "99\n",
      "k= [-1.6380388]\n",
      "d= [-0.3436461]\n"
     ]
    },
    {
     "data": {
      "image/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CRMph6xi4jIZqjYRUQSRsUuIpIwKnYRkYRRsYuIJIyKXUQkYVTsIiIJo2IXEUmY/wXUGP+NVx9BjQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for i in range(100):\n",
    "    update()#更新权值\n",
    "    print(W)#打印当前权值\n",
    "    print(i)#打印迭代次数\n",
    "    O = np.sign(np.dot(X,W))#计算当前输出  \n",
    "    if(O == Y).all(): #如果实际输出等于期望输出，模型收敛，循环结束\n",
    "        print('Finished')\n",
    "        print('epoch:',i)\n",
    "        break\n",
    "\n",
    "#正样本\n",
    "x1 = [0,1]\n",
    "y1 = [1,0]\n",
    "#负样本\n",
    "x2 = [0,1]\n",
    "y2 = [0,1]\n",
    "\n",
    "#计算分界线的斜率以及截距\n",
    "k = -W[1]/W[2]\n",
    "d = -W[0]/W[2]\n",
    "print('k=',k)\n",
    "print('d=',d)\n",
    "\n",
    "xdata = (-2,3)\n",
    "\n",
    "plt.figure()\n",
    "plt.plot(xdata,xdata*k+d,'r')\n",
    "plt.scatter(x1,y1,c='b')\n",
    "plt.scatter(x2,y2,c='y')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
